package com.zhuzg.controller;


import com.zhuzg.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("account")
@Primary
public class AccountController {

    @Resource  // jdk  注解  根据名字从容器查找


    // spring 注解 根据类型从容器当中查找
    // 如果容器当中有重名的对象，则可能报错，解决办法 1）@Qualifier("")
    //  办法2）： 在实例化的时候加上 @Primary  ，这样重名的时候优先加载这个
    @Autowired
    AccountService accountService;

    /**
     * 扣减个人账户的金额
     * @param userId
     * @return
     */
    @RequestMapping("deduce")
    public String deduce(@RequestParam("userId") Integer userId,
                         @RequestParam("money")BigDecimal money){

        accountService.deduceMoney(userId,money);
        return "ok";


    }

}
